

/**
 * FrameLayout R.block_top_adjust_view
 */
import { AstContext } from "../../../context";
import { Pages } from "../Pages";
import { PageVisitor } from "../pageVisitor";
import { createToIndex } from "./createToIndex";
import { createToTitle } from "./createToTitle";

export function parseBlockTopAdjustView(visitor: PageVisitor, ast: AutoJs.UiObject, ctx: AstContext) {
    const scrollView = ctx.bfsOne(ast, (node) => {
        return node.className() === `android.widget.HorizontalScrollView` && node.visibleToUser()
    })
    if (scrollView) {
        const node = ctx.bfsOne(scrollView, it => ctx.filterChildren(it, a => a.className() === `android.widget.FrameLayout`).length === 5)
        if (!node) return true;
        ctx.set(`toSecondTab`, createToIndex(node, ctx, `secondTabIndex`))
        ctx.set(`toSecondTabTitle`, createToTitle(node, ctx, `secondTab`))
        ctx.eachChild(node, (it, index) => {
            const selected = it.selected()
            if (selected) {
                const title = ctx.getText(it)
                switch (title) {
                    case '直播':
                        ctx.set('currentPage', Pages.homeLiveLive)
                        break;
                    case '热门':
                        ctx.set('currentPage', Pages.homeLiveHot)
                        break;
                    case '朋友':
                        ctx.set('currentPage', Pages.homeLiveFriend)
                        break;
                    case '放映厅':
                        ctx.set('currentPage', Pages.homeLiveMove)
                        break;
                    case '生活':
                        ctx.set('currentPage', Pages.homeLiveLife)
                        break;
                    default:
                        ctx.set('currentPage', Pages.homeLiveLive)
                        break;
                }
                ctx.set('secondTabIndex', index)
                ctx.set('secondTab', title)
            }
        })
    }
    return true;
}
